package com.hmall.cart.listener;

import com.hmall.cart.service.ICartService;
import com.hmall.common.constant.MQConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Slf4j
@Component
public class OrderCaetListener {
    @Autowired
    private ICartService iCartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstant.CART_CLEAR_QUEUE),
            exchange = @Exchange(name =MQConstant.TRADE_TOPIC ,type = ExchangeTypes.TOPIC),
            key = MQConstant.ORDER_CREATE_KEY
    ))
    public void norderPaye(Collection<Long> msg) {
        log.info("OrderCaetListener.norderPaye: {}", msg);
        iCartService.removeByItemIds(msg);
    }
}



